import axios from 'axios';
import query from 'query-string';

const BASE_URL = '/promotion/seckill/item';


export interface SeckillItemParam {
    seckillId?: number;
    page?: number;
    size?: number;
    sort?: Array<string>;
}

export interface SeckillItemResponse {
    id?: number;
    seckillId: number;
    skuId?: number;
    skuName?: string;
    skuDescs?: string;
    skuImg?: string;
    spuName?: string;
    startTime?: string;
    endTime?: string;
    initStockQuantity?: number;
    availableStockQuantity?: number;
    warmUpStatus?: number;
    skuPrice?: string;
    seckillPrice?: string;
    status?: number;

    createdBy?: string;
    updatedBy?: string;
    createdAt?: string;
    updatedAt?: string;
}

export interface SeckillItemSaveCommand {
    id?: number;
    seckillId: number;
    skuId?: number;
    skuName?: string;
    skuDescs?: string;
    skuImg?: string;
    spuName?: string;
    startTime?: string;
    endTime?: string;
    initStockQuantity?: number;
    availableStockQuantity?: number;
    warmUpStatus?: number;
    skuPrice?: string;
    seckillPrice?: string;
    status?: number;

}

export interface SeckillItemResponseList {
    list: SeckillItemResponse[];
    total: number;
}


// 通过SeckillItemParam参数获取分页列表
export function pageSeckillItem(params: SeckillItemParam) {
    return axios.get<SeckillItemResponseList>(`${BASE_URL}/page`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    })
}

// 通过id获取秒杀item信息
export function getSeckillItem(id: number) {
    return axios.get<SeckillItemResponse>(`${BASE_URL}/${id}`);
    
}

export function listSeckillItem(params: SeckillItemParam) {
    return axios.get<SeckillItemResponse[]>(`${BASE_URL}/list`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    });
}


// 添加秒杀item
export function addSeckillItem(params: SeckillItemSaveCommand) {
    return axios.post(`${BASE_URL}`, params);
}

// 更新秒杀item
export function updateSeckillItem(params: SeckillItemSaveCommand) {
    return axios.put(`${BASE_URL}`, params);
}

// 批量删除秒杀item
export function deleteSeckillItem(ids: number | Array<number>) {
    return axios.delete(`${BASE_URL}/${ids}`);
}
